package cn.gjxblog.scheduling.jdk.executor;

import cn.gjxblog.base.LogUtils;

import java.util.Random;
import java.util.concurrent.Callable;

/**
 * 带返回值的的作业
 */
public class MyCallableTask implements Callable {
    /**
     * 作业名
     */
    private String name;

    public MyCallableTask(String name) {
        this.name = name;
    }

    @Override
    public Object call() throws Exception {
        long start = System.currentTimeMillis();

        System.out.println(LogUtils.getThreadInfo()+"作业"+name+"正在执行~~");
        try {
            Random random = new Random();
            Thread.sleep(1000*(random.nextInt(5)+1));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();

        System.out.println(LogUtils.getThreadInfo()+"作业"+name+"执行结束~~ 共执行"+(end-start)/1000+"秒");
        return "计算结果";
    }
}
